import com.github.pagehelper.PageInfo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import zl.bean.Admin;
import zl.bean.Category;
import zl.config.MainConfig;
import zl.service.AdminService;
import zl.service.CategoryService;
import zl.service.UserService;

import java.sql.SQLException;
import java.util.List;

//指定运行时
@RunWith(SpringJUnit4ClassRunner.class)
//指定Spring的配置文件或配置类
//@SpringJUnitConfig(locations = "classpath:applicationContext.xml")
@SpringJUnitConfig(classes = MainConfig.class)
public class T1 {

    @Autowired
    private UserService userService;

    @Autowired
    private AdminService adminService;
    @Autowired
    private CategoryService categoryService;

    @Test
    public void test1() throws Exception {
        List<Admin> list = adminService.selectAllAdmin();
        list.forEach(System.out::println);
    }

    @Test
    public void test3() throws SQLException {
        /*List<Category> users = categoryService.selectAllCategory();

        users.forEach(item -> System.out.println(item));
        System.out.println("----------------");

        PageInfo<Category> pageInfo = new PageInfo<>(users);
        System.out.println(pageInfo);
        System.out.println("总记录数：" + pageInfo.getTotal());
        System.out.println("当前页：" + pageInfo.getPageNum());
        System.out.println("总页数：" + pageInfo.getPages());
        System.out.println("上一页：" + pageInfo.getPrePage());
        System.out.println("下一页：" + pageInfo.getNextPage());
        System.out.println("是否是首页：" + pageInfo.isIsFirstPage());
        System.out.println("是否是尾页：" + pageInfo.isIsLastPage());*/
        PageInfo<Category> categoryPageInfo = categoryService.selectByPage(1, null);
        categoryPageInfo.getList().forEach(System.out::println);
        System.out.println("总记录数：" + categoryPageInfo.getTotal());
        System.out.println("当前页：" + categoryPageInfo.getPageNum());
        System.out.println("总页数：" + categoryPageInfo.getPages());
        System.out.println("上一页：" + categoryPageInfo.getPrePage());
        System.out.println("下一页：" + categoryPageInfo.getNextPage());
        System.out.println("是否是首页：" + categoryPageInfo.isIsFirstPage());
        System.out.println("是否是尾页：" + categoryPageInfo.isIsLastPage());
    }


}
